import React, { useCallback, useEffect, useState, useRef } from "react";

import { SearchSimpleTable } from "@/views/components/SearchTable/index";
import { useTableConfig } from "@/views/components/SearchTable/hooks/useTableConfig";
import LeftBtns from "./components/Actions/LeftBtns";
import RightBtns from "./components/Actions/RightBtns";

import { getColumns } from "./columns";

import { queryMemberPriceApplyList } from "./service";

const partialQueryMemberPriceApplyList = (_params, other) => {
	const params = { ..._params };
	if (!params.startTime) {
		delete params.dateType;
	}
	return queryMemberPriceApplyList(params, other);
};

// 0 待审核 1 使用中 2 失败 3 作废
const statusApi = {
	0: p => partialQueryMemberPriceApplyList(p, { status: 0 }),
	1: p => partialQueryMemberPriceApplyList(p, { status: 1 }),
	2: p => partialQueryMemberPriceApplyList(p, { status: 2 }),
	3: p => partialQueryMemberPriceApplyList(p, { status: 3 })
};

const ListTable = ({ status = 0 }) => {
	const cbRef = useRef(() => {});
	const { columns } = getColumns({ cbRef: cbRef, status });

	// const tableRequest = tableRequestMock1;
	const tableKey = "memberPriceTable";
	const {
		selectedKeys,
		selectedRows,
		fetchList,
		dataSource,
		form,
		query,
		pagination,
		updateDataSource,
		updateSearchQuery,
		updatePaginationParams,
		searchSimpleTableProps
	} = useTableConfig({
		tableKey,
		rowKey: "id",
		// ///
		columns,
		tableRequest: statusApi[status],
		autoFetch: true,
		hasPagination: true,
		hasQuickSearch: true,
		beforeQuerySearch: false,
		resetSourceData: false,
		hasColsSetting: true,
		hasToggleSearchForm: true,
		columnResize: true
		// hasQueryLocation: "/views/goods/shop"
	});
	cbRef.current = () => {
		fetchList();
	};

	return (
		<>
			<SearchSimpleTable
				key={tableKey}
				leftBtns={<LeftBtns onSubmitSuccess={cbRef.current} status={status} />}
				rightBtnsContent={RightBtns}
				rightBtnsContentProps={null}
				mounted={false}
				{...searchSimpleTableProps}
			/>
		</>
	);
};
export default React.memo(ListTable, () => {
	return true;
});
